//bange_behavior.hpp
//Copyright (C) 2010-2011 Oscar (.teri) Triano

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef _bange_behavior_
#define _bange_behavior_

#include <iostream>
#include <map>
#include <cstring>
#include <lua5.1/lua.hpp>
#include <SFML/Graphics.hpp>
#include <bange_base.hpp>

using namespace std;

namespace bange{
	
	struct function{
		int function;
		bool enabled;
	};
	
	struct schedulefunction{
		int function;
		float time;
		float storetime;
		bool enabled;
	};
	
	class behavior: public bange::base{
		protected:
			int data;
		public:
			int events;
		protected:
			bool eventhandler;
			bool processfunctions;
			bool processschedulefunctions;
			map<const void *, bange::function *>functions;
			map<const void *, bange::schedulefunction *>schedulefunctions;
		public:
			behavior(lua_State *);
			bool NewIndex(lua_State *);
			bool Index(lua_State *);
			void SetEventHandler(bool);
			void AddFunction(lua_State *);
			bool SetFunction(lua_State *);
			bool QuitFunction(lua_State *);
			void AddScheduleFunction(float, lua_State *);
			bool SetScheduleFunction(lua_State *);
			void ResetScheduleFunction(lua_State *);
			bool QuitScheduleFunction(lua_State *);
			void ExecuteEvents(int, int, sf::Event &, lua_State *);
			void ExecuteFunctions(int, lua_State *);
			void ExecuteScheduleFunctions(int, float, lua_State *);
			void CleanVM(lua_State *);
			~behavior();

			static void RegisterVM(lua_State *);
			
	};

}

static int bangebehavior_AddFunction(lua_State *);
static int bangebehavior_SetFunction(lua_State *);
static int bangebehavior_QuitFunction(lua_State *);
static int bangebehavior_AddScheduleFunction(lua_State *);
static int bangebehavior_SetScheduleFunction(lua_State *);
static int bangebehavior_ResetScheduleFunction(lua_State *);
static int bangebehavior_QuitScheduleFunction(lua_State *);

#endif
